// #include <cstdio>
#include <iostream>
#include <vector>
/*
#include <math.h>
define Turntable_OFFSET 20
#define SARM_OFFSET 30 // 小臂
#define BARM_OFFSET 25
#define Grippers_OFFSET 9

#define BASE_HEIGHT 6
#define L1 8 // 大臂长度
#define L2 8.5

struct ServoDegree
{
    double theta_1, theta_2, theta_3;
};

ServoDegree GetServoDegree(double rx, double ry, double rz)
{
    ServoDegree aim;
    aim.theta_1 = atan2f(ry, rx); // 转台角度
    double xe = rx - Grippers_OFFSET * cos(aim.theta_1);
    double ye = ry - Grippers_OFFSET * sin(aim.theta_1);
    double x_e_2 = rz + 2.5 - BASE_HEIGHT;              // 末端相对于转台的x轴，高度轴
    double y_e_2 = sqrt(pow(xe, 2) + pow(ye, 2)); // 末端相对于转台的y轴，向前的轴。(0,0)是转台圆心
    // double z_e_2 = 0;                             // 末端相对于转台的z轴，向左右的轴。
    double L3 = sqrt(pow(x_e_2, 2) + pow(xe, 2) + pow(ye, 2));
    double theta_a = acos((L1 * L1 + L3 * L3 - L2 * L2) / (2 * L1 * L3));
    double theta_b = atan2(y_e_2, x_e_2);
    aim.theta_2 = theta_b - theta_a; // 大臂角度 竖直往前是正
    double theta_d = acos((L1 * L1 + L2 * L2 - L3 * L3) / (2 * L1 * L2));
    aim.theta_3 = theta_d - (3.1415 / 2) - aim.theta_2; // 小臂角度 水平向上为正
                                                        // 以上为实际角度
    aim.theta_1 *= 57.3;
    // aim.theta_2 = 90 - aim.theta_2 * 57.3  + BARM_OFFSET;
    // aim.theta_3 = -(aim.theta_3 * 57.3) + SARM_OFFSET;
    aim.theta_2 = aim.theta_2 * 57.3 ;
    aim.theta_3 = -(aim.theta_3 * 57.3) ;

    // if (aim.theta_1 < 0 || aim.theta_1 > 180 || aim.theta_3 < 5 || aim.theta_3 > 80 || aim.theta_2 < 20 || aim.theta_2 > 120)
    // {
    //     aim.theta_2 = 0;
    //     return aim;
    // }
    return aim;
}

int main()
{
    ServoDegree aim = GetServoDegree(0, 15, 8);
    printf("%f,%f,%f\n", aim.theta_1 , aim.theta_2 , aim.theta_3 );
}
*/

class Screen
{
    friend class Window_mgr;
public:
    typedef std::string::size_type pos;
    Screen() = default;
    Screen(int width, int height, char c) : width(width), height(height) ,content(height*width, c){}
    Screen(char c) : Screen(3, 3, c){}  //委托构造函数
    inline Screen &set(char c)
    {
        content[cursor] = c;
        return *this;   //返回this指向的对象以便于链式
    }
    char get() const
    {
        return content[cursor];
    }
    inline char get(pos ht, pos wd) const;
    Screen &move(pos r, pos c);
    Screen &display(std::ostream &os)
    {
        do_display(os);
        return *this;
    }
    const Screen &display(std::ostream &os) const
    {
        do_display(os);
        return *this;
    }

private:
    pos cursor = 0;
    pos height = 0, width = 0;
    std::string content;
    void do_display(std::ostream &os) const
    {
        os << content << std::endl;
    }
};

inline Screen &Screen::move(pos r, pos c)
{
    pos row = r * width;
    cursor = row + c;
    return *this;
}
char Screen::get(pos r, pos c) const
{
    pos row = r * width;
    return content[row + c];
}

class Window_mgr
{  
public:
    using ScreenIndex = std::vector<Screen>::size_type;
    void clear(ScreenIndex);
    ScreenIndex addScreen(const Screen &s);
    Screen &getScreen(ScreenIndex i);
private:
    std::vector<Screen> screens{Screen(1, 6, '0')};
};

Screen &Window_mgr::getScreen(ScreenIndex i)
{
    return *(begin(screens) + i);
}
void Window_mgr::clear(ScreenIndex i)
{
    Screen &s = screens[i];
    s.content = std::string(s.height * s.width, '-');
}

Window_mgr::ScreenIndex Window_mgr::addScreen(const Screen &new_s)
{
    screens.push_back(new_s);
    return screens.size() - 1;
}

class Account{
public:
    void calculate() { amount += amount * i_rate; }
    static double rate() { return i_rate; }
    static void rate(double);

private:
    std::string owner;
    double amount;
    static double i_rate;   //所有实例共享
    static double init_rate();
};

double Account::i_rate = Account::init_rate();  //静态成员要在类外重新定义
double Account::init_rate(){
    return 3;
}
void Account::rate(double newrate)
{
    i_rate = newrate;
}

int main()
{
    /* code */
    // Window_mgr w;
    // w.getScreen(0).move(0, 0).set('#').move(0, 1).set('7').display(std::cout);
    // w.clear(0);
    // size_t i = w.addScreen(Screen(2, 2, 'n'));
    // w.getScreen(i).display(std::cout);
    // Screen one('g');
    // one.display(std::cout);

    double r;
    Account::rate(9);
    r = Account::rate();
    std::cout << r;
    return 0;
}
